IDL_Integer
The IDL_Integer class contains static methods that are available for integers. In addition, because IDL_Integer is a subclass of IDL_Number, all of the IDL_Number and IDL_Variable methods are also available.
Superclasses
IDL_Integer
- BitLength: Returns the number of bits in the current value, ignoring leading zero bits.
- BitGet: Returns the requested bit associated with the current value.
- BitSet: Returns a scalar or array of values after setting the bits on the current value.
- BitShift: Returns a scalar or array of values after shifting the bits on the current value.
- ToASCII: Converts the current number to an ASCII string.
- ToBinary: Converts the current number to a binary string.
- ToHex: Converts the current number to a hex string.
- ToOctal: Converts the current number to an octal string.
IDL_Integer::BitLength
The IDL_Integer::BitLength method returns the number of bits in the scalar or array, ignoring any leading zero bits.
Examples
num = [0, 1, 2, 7, 16385]
PRINT, num.BitLength( )
IDL prints:
0 1 2 3 15
Syntax
Result = var.BitLength( )
Return Value
A scalar byte or a byte array of the same dimensions as the variable. Each element in the Result will contain the number of bits in the corresponding value.
Arguments
None.
Keywords
None.
IDL_Integer::BitGet
The IDL_Integer::BitGet method returns a byte array of the variable.
Examples
Print the 3rd bit value of each element of an array:
num = INDGEN(8)
PRINT, num.BitGet( 3 )
IDL prints:
0 0 0 0 1 1 1 1
Syntax
Result = var.BitGet( Location )
Return Value
A byte array containing the bit value of each element of the variable.
Arguments
Location
A scalar integer designating the location of the requested bit.
Keywords
None.
IDL_Integer::BitSet
The IDL_Integer::BitSet method returns the variable after setting the bit or bit values.
Examples
Print the value of a variable after setting the bits on each element:
num = [0, 0, 0, 0]
PRINT, num.BitSet([1, 2, 3, 4])
IDL prints:
1 2 4 8
Syntax
Result = var.BitSet( Location [, /CLEAR] [, /FLIP])
Return Value
The scalar or array of values of the variable after their bits have been set.
Arguments
Location
The location of which bit to set.
Keywords
CLEAR
Set this keyword to clear the bits specified by Location.
FLIP
Set this keyword to flip the bits specified by Location.
IDL_Integer::BitShift
The IDL_Integer::BitShift method returns a scalar or array after a bit shift operation.
Examples
Print the value of a number after shifting the bit:
num = [1, 10, 100]
; [ShiftRightOnePosition, ShiftLeftFivePositions, NoShift]
PRINT, num.BitShift( [-1, 5, 0] )
PRINT, num.BitShift( [-1, 5, 0], /CIRCULAR )
IDL prints:
0 320 100
-32768 320 100
Syntax
Result = var.BitShift( Direction [, /CIRCULAR] )
Return Value
The value of the scalar or array after the bit shift operation.
Arguments
Direction
A scalar or array containing the number of bit positions and the direction of the shift.
If the element of Direction is positive, the related element of the array is left-shifted that many bit positions, with 0 bits filling vacated positions.
If the element of Direction is negative, the related element of the array is right-shifted that many bit positions, with 0 bits filling vacated positions.
Keywords
CIRCULAR
Set this keyword to shift the number circularly (i.e., shifting right a value of 1 would return -32768).
IDL_Integer::ToASCII
The IDL_Integer::ToASCII method returns a string containing the ASCII representation of a number or array of numbers.
Examples
Print the ASCII string value of an array:
num = [72, 101, 108, 108, 111]
PRINT, num.ToASCII( )
IDL prints:
Hello
Print the ASCII string values of a two-dimensional array:
num = [[73,68,76], $
[105,115,32], $
[102,117,110]]
HELP, num.ToASCII( )
PRINT, num.ToASCII( ), /IMPLIED
IDL prints:
<Expression> STRING = Array[3]
IDL
is
fun
Syntax
Result = var.ToASCII( )
Return Value
A scalar string or string array containing the ASCII values.
If var is a scalar or 1-dimensional array then the result will be a scalar string with all of the ASCII characters concatenated together. If var is a multi-dimensional array then the result will be a string array of one less dimension, where the characters in the first dimension have been concatenated (see the examples above).
Arguments
None.
Keywords
None.
IDL_Integer::ToBinary
The IDL_Integer::ToBinary method returns a string containing the binary representation of the number.
Examples
Print the hex value of a number:
num = [65385, 976]
PRINT, num.ToBinary( ), /IMPLIED
PRINT, num.ToBinary( WIDTH=16 ), /IMPLIED
IDL prints:
1111111101101001
1111010000
1111111101101001
0000001111010000
Syntax
Result = var.ToBinary( [WIDTH=value] )
Return Value
A scalar string or string array containing the binary representation. If var is an array then the result will be a string array of the same dimensions as the input.
Arguments
None.
Keywords
WIDTH
Set the WIDTH to an integer in the range 0–255 indicating the number of digits in the result. If the binary representation is smaller than the width, then the result will be padded with 0's at the front. If WIDTH=0 or is not specified, then no zero padding is used.
Note: If the binary representation is larger than the width, then the result will be filled with asterisks (*) instead of the number.
IDL_Integer::ToHex
The IDL_Integer::ToHex method returns a string containing the hex value of the number.
Examples
Print the hex value of a number:
num = [65385, 976]
PRINT, num.ToHex( ), /IMPLIED
PRINT, num.ToHex( WIDTH=8 ), /IMPLIED
IDL prints:
FF69
3D0
0000FF69
000003D0
Syntax
Result = var.ToHex( [/LOWER] [, WIDTH=value] )
Return Value
A scalar string or string array containing the hex values. If var is an array then the result will be a string array of the same dimensions as the input.
Arguments
None.
Keywords
LOWER
Set this keyword to use lowercase characters for the hexadecimal digits. The default is uppercase characters.
WIDTH
Set the WIDTH to an integer in the range 0–255 indicating the number of digits in the result. If the hex representation is smaller than the width, then the result will be padded with 0's at the front. If WIDTH=0 or is not specified, then no zero padding is used.
Note: If the hex representation is larger than the width, then the result will be filled with asterisks (*) instead of the number.
IDL_Integer::ToOctal
The IDL_Integer::ToOctal method returns a string containing the octal value of the number.
Examples
Print the octal value of a number:
num = [65385, 976]
PRINT, num.ToOctal( ), /IMPLIED
PRINT, num.ToOctal( WIDTH=8 ), /IMPLIED
IDL prints:
177551
1720
00177551
00001720
Syntax
Result = var.ToOctal( [WIDTH=value] )
Return Value
A scalar string or string array containing the octal values. If var is an array then the result will be a string array of the same dimensions as the input.
Arguments
None.
Keywords
WIDTH
Set the WIDTH to an integer in the range 0–255 indicating the number of digits in the result. If the octal representation is smaller than the width, then the result will be padded with 0's at the front. If WIDTH=0 or is not specified, then no zero padding is used.
Note: If the octal representation is larger than the width, then the result will be filled with asterisks (*) instead of the number.
Version History
8.4 |
Introduced |
8.6 |
Add WIDTH keyword to ToBinary and ToOctal. Add LOWER and WIDTH keywords to ToHex. |
See Also
Static Methods and Attributes, Variable Attributes, IDL_Number, IDL_Pointer, IDL_String, IDL_Variable